/*
 * @Author: EyeSklear 1814580085@qq.com
 * @Date: 2024-01-10 13:00:15
 * @LastEditors: EyeSklear 1814580085@qq.com
 * @LastEditTime: 2024-01-22 16:19:26
 * @FilePath: \Scene_Back\src\audio\audio.module.ts
 * @Description:
 *
 * Copyright (c) 2024 by EyeSklear , All Rights Reserved.
 */
import { Module } from '@nestjs/common';
import { AudioService } from './audio.service';
import { AudioController } from './audio.controller';
import { diskStorage } from 'multer';
import { MulterModule } from '@nestjs/platform-express';
import { extname, join } from 'path';
import { Audio } from './entities/audio.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';
@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: function (req, fileName, callback) {
          try {
            callback(null, path.resolve(process.env.FILE_PATH + '/audio'));
          } catch (error) {
            console.error('Error in setting audio destination:', error);
          }
        },
        filename: (_, file, callback) => {
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
    TypeOrmModule.forFeature([Audio]),
  ],
  controllers: [AudioController],
  providers: [AudioService],
  exports: [AudioService],
})
export class AudioModule {}
